﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data;
using Royalsoft.Common;

namespace NJL.Web
{
    public partial class HolidayVilla : BasePageVisitor
    {
        private readonly BLL.NJL_COMPANY bll = new BLL.NJL_COMPANY();
        private readonly BLL.NJL_COMPANY_SERVICE bllService = new BLL.NJL_COMPANY_SERVICE();
        private readonly BLL.NJL_SYS_NEWS bllSysNews = new BLL.NJL_SYS_NEWS();
        private readonly BLL.NJL_ATTRACTION bllAttraction = new BLL.NJL_ATTRACTION();

        protected IList<Model.NJL_COMPANY> LIST_COMPANY;
        protected IList<Model.NJL_COMPANY_SERVICE> LIST_SERVICE;
        protected IList<Model.NJL_SYS_NEWS> LIST_FLASH;
        protected IList<Model.NJL_ATTRACTION> LIST_ATTRACTION;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
                base.LoadPageSeoInformation("度假山庄");
            }
        }

        public void LoadData()
        {
            if (WEBSITE_FOCUS_CITY_CODE != "")
            {
                LIST_FLASH = bllSysNews.GetModelList(10, " NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' AND IS_PUBLISH=1 AND IS_INDEX=1 AND TYPE_CODE='13' ", "SORT DESC,PUBLISH_DATE_TIME DESC");

                LIST_ATTRACTION = bllAttraction.GetModelList(10, " NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' and AREA_CODE='" + WEBSITE_FOCUS_CITY_CODE + "' and IS_PUBLISH=1 and IS_INDEX=1 ", "SORT DESC,PUBLISH_DATE_TIME DESC");

                #region 度假山庄

                // LIST_COMPANY = bll.GetModelList(100, " NJL_COMPANY.NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' AND NJL_COMPANY.AUDIT_STATE=1 AND NJL_COMPANY.TYPE_CODE='2' and NJL_COMPANY.AREA_CODE='" + WEBSITE_FOCUS_CITY_CODE + "'", "NJL_COMPANY.CREATE_DATE_TIME DESC");

                DataSet ds = bll.GetList("NJL_COMPANY.NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' AND NJL_COMPANY.AUDIT_STATE=1 AND NJL_COMPANY.TYPE_CODE='2' and NJL_COMPANY.AREA_CODE='" + WEBSITE_FOCUS_CITY_CODE + "'");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    pager.InnerHtml = Pager.GetPageNum(ds, rptHolidayValla, 5, null, "/"+WEBSITE_FOCUS_CITY_NAME_PINYIN + "/djsz/");
                }
                #endregion
                #region 度假山庄第一条记录
                ds = bllSysNews.GetList(1, "TYPE_CODE='16' and IS_PUBLISH=1 AND IS_INDEX=1 and NJL_SYS_BASE_ID='" + WEBSITE_CODE + "'", "SORT DESC,PUBLISH_DATE_TIME desc");
                rptImageNewsList.DataSource = ds;
                rptImageNewsList.DataBind();
                #endregion
                #region 度假山庄新闻列表
                ds = bllSysNews.GetList(7, "TYPE_CODE='16' and IS_PUBLISH=1 AND IS_INDEX=1 and NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' and ID not in(select top 1 ID from NJL_SYS_NEWS where TYPE_CODE='16' and  IS_PUBLISH=1 AND IS_INDEX=1 and NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' order by SORT DESC,PUBLISH_DATE_TIME desc)", "SORT DESC,PUBLISH_DATE_TIME desc");
                rptNewsList.DataSource = ds;
                rptNewsList.DataBind();
                #endregion
                #region 周边同类
                ds = bll.GetList(6, " NJL_COMPANY.NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' AND NJL_COMPANY.AUDIT_STATE=1 AND NJL_COMPANY.TYPE_CODE='2' and NJL_COMPANY.AREA_CODE!='" + WEBSITE_FOCUS_CITY_CODE + "' AND NJL_COMPANY.IMAGE_CODE is not null AND NJL_COMPANY.IMAGE_CODE <> ''", "NJL_COMPANY.SORT DESC,NJL_COMPANY.CREATE_DATE_TIME DESC");
                rptPeriphery.DataSource = ds;
                rptPeriphery.DataBind();
                #endregion
                #region 商务会议
                ds = bllSysNews.GetList(7, "TYPE_CODE='39' and IS_PUBLISH=1 AND IS_INDEX=1 and NJL_SYS_BASE_ID='" + WEBSITE_CODE + "'", "SORT DESC,PUBLISH_DATE_TIME desc");
                rptMeeting.DataSource = ds;
                rptMeeting.DataBind();
                #endregion
            }
            else
            {
                LIST_FLASH = bllSysNews.GetModelList(10, " NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' AND IS_PUBLISH=1 AND IS_INDEX=1 AND TYPE_CODE='13' ", "SORT DESC,PUBLISH_DATE_TIME DESC");

                LIST_ATTRACTION = bllAttraction.GetModelList(10, " NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' and IS_PUBLISH=1 and IS_INDEX=1 ", "SORT DESC,PUBLISH_DATE_TIME DESC");

                #region 度假山庄

                // LIST_COMPANY = bll.GetModelList(100, " NJL_COMPANY.NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' AND NJL_COMPANY.AUDIT_STATE=1 AND NJL_COMPANY.TYPE_CODE='2' and NJL_COMPANY.AREA_CODE='" + WEBSITE_FOCUS_CITY_CODE + "'", "NJL_COMPANY.CREATE_DATE_TIME DESC");

                DataSet ds = bll.GetList("NJL_COMPANY.NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' AND NJL_COMPANY.AUDIT_STATE=1 AND NJL_COMPANY.TYPE_CODE='2' ");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    pager.InnerHtml = Pager.GetPageNum(ds, rptHolidayValla, 5, null, "/djsz/");
                }
                #endregion
                #region 度假山庄第一条记录
                ds = bllSysNews.GetList(1, "TYPE_CODE='16' and IS_PUBLISH=1 AND IS_INDEX=1 and NJL_SYS_BASE_ID='" + WEBSITE_CODE + "'", "SORT DESC,PUBLISH_DATE_TIME desc");
                rptImageNewsList.DataSource = ds;
                rptImageNewsList.DataBind();
                #endregion
                #region 度假山庄新闻列表
                ds = bllSysNews.GetList(7, "TYPE_CODE='16' and IS_PUBLISH=1 AND IS_INDEX=1 and NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' and ID not in(select top 1 ID from NJL_SYS_NEWS where TYPE_CODE='16' and  IS_PUBLISH=1 AND IS_INDEX=1 and NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' order by SORT DESC,PUBLISH_DATE_TIME desc)", "SORT DESC,PUBLISH_DATE_TIME desc");
                rptNewsList.DataSource = ds;
                rptNewsList.DataBind();
                #endregion
                #region 周边同类
                ds = bll.GetList(6, " NJL_COMPANY.NJL_SYS_BASE_ID='" + WEBSITE_CODE + "' AND NJL_COMPANY.AUDIT_STATE=1 AND NJL_COMPANY.TYPE_CODE='2' AND NJL_COMPANY.IMAGE_CODE is not null AND NJL_COMPANY.IMAGE_CODE <> '' ", "NJL_COMPANY.SORT DESC,NJL_COMPANY.CREATE_DATE_TIME ASC");
                rptPeriphery.DataSource = ds;
                rptPeriphery.DataBind();
                #endregion
                #region 商务会议
                ds = bllSysNews.GetList(7, "TYPE_CODE='39' and IS_PUBLISH=1 AND IS_INDEX=1 and NJL_SYS_BASE_ID='" + WEBSITE_CODE + "'", "SORT DESC,PUBLISH_DATE_TIME desc");
                rptMeeting.DataSource = ds;
                rptMeeting.DataBind();
                #endregion
            }
        }

        protected void rptHolidayValla_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView drv = (DataRowView)e.Item.DataItem;
                string id = drv["ID"].ToString();
                Repeater rtp = e.Item.FindControl("rptService") as Repeater;
                DataSet ds = bllService.GetList(4, "NJL_COMPANY_ID='" + id + "'", "SORT DESC,CREATE_DATE_TIME desc");
                rtp.DataSource = ds;
                rtp.DataBind();
            }
        }


    }
}